package com.itboye.mengwu.app.ui.mymeng.personsettings;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.SPUtils;
import com.itboye.mengwu.R;
import com.itboye.mengwu.app.MainApplication;
import com.itboye.mengwu.app.logincontroller.ILoginState;
import com.itboye.mengwu.app.logincontroller.LoginController;
import com.itboye.mengwu.app.logincontroller.LoginedState;
import com.itboye.mengwu.app.logincontroller.UnLoginState;
import com.itboye.mengwu.app.ui.mymeng.AboutActivity;
import com.itboye.mengwu.app.ui.mymeng.ActivityGeRenData;
import com.itboye.mengwu.app.ui.web.WebActivity;
import com.itboye.mengwu.main.FragmentShopcart;
import com.itboye.mengwu.main.WoMengFragment;
import com.umeng.common.message.Log;
import com.umeng.message.PushAgent;

@SuppressLint("ResourceAsColor")
public class SettingActivity extends BaseActivity implements OnClickListener {
	private ImageView imgBack;
	private RelativeLayout relayoutZiLiao, relayoutZhangHuAnQuan,
			relayoutMessage, relayoutCustomer, relayoutVIP, relayoutAbout,
			btn_exit;
	private TextView txt_title;
	ImageView back;
	String uid;
	String psw;
	String abouturl = "http://www.moodwo.com/Public/html/about.html";
	String APP_URL = "http://www.moodwo.com/index.php/Webview";

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.fragment_settings;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		txt_title.setText("设置");
		uid = SPUtils.get(this, null, SpPublicParams.UID, "") + "";
		psw = SPUtils.get(this, null, SpPublicParams.PASSWORD, "") + "";
		if ("".equals(uid)) {
			btn_exit.setVisibility(View.GONE);

		}
	}

	@Override
	public void onClick(View view) {
		Intent intent;
		switch (view.getId()) {

		case R.id.back:
			finish();
			break;
		case R.id.relayoutZiLiao:
			LoginController.queryMyMessae(this, null);
			break;
		case R.id.relayoutZhangHuAnQuan:

			intent = new Intent(this, SaFeActivity.class);
			startActivity(intent);
			break;
		// case R.id.relayoutMessage:
		// intent = new Intent(this, AboutActivity.class);
		// startActivity(intent);
		// break;
		case R.id.relayoutCustomer:
			// Intent intent2 = new Intent(this, WebActivity.class);
			// intent2.putExtra("title", "联系客服");
			// intent2.putExtra("url", APP_URL + "/kefu?uid=" + uid + "&psw="
			// + psw);
			// Log.e("hu", "uid=" + uid + "psw=" + psw);
			// startActivity(intent2);

			Intent intent2 = new Intent();
			intent2.setAction(Intent.ACTION_CALL);
			// url:统一资源定位符
			// uri:统一资源标示符（更广）
			intent2.setData(Uri.parse("tel:"
					+ SPUtils.get(getApplicationContext(), null,
							SpPublicParams.KeFuPhone, "")));
			// 开启系统拨号器
			startActivity(intent2);
			break;
		case R.id.relayoutVIP:
			// Intent intent3 = new Intent(this, WebActivity.class);
			// intent3.putExtra("title", "会员");
			// intent3.putExtra("url", APP_URL + "/vip/index?uid=" + uid
			// + "}&psw=" + psw + "");
			//
			// startActivity(intent3);
			LoginController.vip(this, "会员", APP_URL + "/vip/index?uid=" + uid
					+ "}&psw=" + psw + "");
			break;
		case R.id.relayoutAbout:

			// Intent intent4 = new Intent(this, WebActivity.class);
			intent = new Intent(this, AboutActivity.class);
			startActivity(intent);
			// intent4.putExtra("title", "关于");
			// intent4.putExtra("url", abouturl);
			// startActivity(intent4);

			break;
		case R.id.btn_exit:
			SPUtils.put(this, null, SpPublicParams.IS_LOGINED, false);
			SPUtils.put(this, null, SpPublicParams.UID, "");
			LoginController.setLoginState(new UnLoginState());
			Intent intent3 = new Intent();
			intent3.setAction("update");
			sendBroadcast(intent3);
			exit();
			finish();
			break;
		default:
			break;
		}
	}

	private void exit() {
		// TODO Auto-generated method stub
		try {
			PushAgent.getInstance(MainApplication.context).deleteAlias(
					(String) SPUtils.get(MainApplication.context, null,
							SpPublicParams.UID, ""), "mengwu");
		} catch (Throwable e) {
			e.printStackTrace();
		}
		SPUtils.put(MainApplication.context, null, SpPublicParams.USER_NAME, "");
		SPUtils.put(MainApplication.context, null, SpPublicParams.USERHEAD, "");
		SPUtils.put(MainApplication.context, null, SpPublicParams.NICK_NAME, "");
		SPUtils.put(MainApplication.context, null, SpPublicParams.UID, "");
		SPUtils.put(MainApplication.context, null, SpPublicParams.SEX, "");
		SPUtils.put(MainApplication.context, null, SpPublicParams.SIGNATURE, "");
		SPUtils.put(MainApplication.context, null, SpPublicParams.PHONE_MODEL,
				"");
		SPUtils.put(MainApplication.context, null, SpPublicParams.VIP, "");
		Intent intent = new Intent(WoMengFragment.AVARTACTION);
		sendBroadcast(intent);
		Intent intent2 = new Intent("changeshopcart");
		sendBroadcast(intent2);
		btn_exit.setVisibility(View.GONE);
	}

}
